package com.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

/**
 * @classDescription:
 * @author:xiayingjie
 * @createTime:16/7/19
 */
@Configuration
public class PropertiesConfig {

    @Configuration
    @Profile("dev")
    @PropertySource(value = {"classpath:db/db-dev.properties","classpath:config/config-dev.properties"})
    static class DEV
    { }

    @Configuration
    @Profile("test")
    @PropertySource(value = {"classpath:db/db-test.properties","classpath:config/config-test.properties"})
    static class TEST
    {
        // nothing needed here if you are only overriding property values
    }

    @Configuration
    @Profile("online")
    @PropertySource(value = {"classpath:db/db-online.properties","classpath:config/config-online.properties"})
    static class OLINE
    {
        // nothing needed here if you are only overriding property values
    }

    //从spring3.1开始推荐使用  废弃PropertyPlaceholderConfigurer 可以基于spring enviroment和属性来源解析
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfig() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}
